package edu.mse.camel.client.core.handlers;

import edu.mse.camel.client.eventbus.pubsub.EventManager;
import edu.mse.camel.client.eventbus.pubsub.ISubscriber;
import edu.mse.camel.client.events.EventIDs;
import edu.mse.camel.client.events.IEvent;
import edu.mse.camel.client.events.server.NotifySessionParticipantChange;
import edu.mse.camel.client.session.team.TEAMMEMBER_STATUS;
import edu.mse.camel.client.session.team.TeamList;

public class NotifyParticipantChangeEventHandler implements ISubscriber{

	@Override
	public void notifyEvent(IEvent e) {
		if (e.getEventID().equalsIgnoreCase(EventIDs.NOTIFY_SESSION_PARTICIPANT_CHANGE_EVENT)){

			NotifySessionParticipantChange npcEvent = (NotifySessionParticipantChange) e;

			if(npcEvent.isInSession()){
				TeamList.getInstance().setMyStatus(TEAMMEMBER_STATUS.SESSION);
			} else {
				TeamList.getInstance().setMyStatus(TEAMMEMBER_STATUS.ONLINE);
				EventManager.getInstance().clearCache();
			}
			
			TeamList.getInstance().updateTeamMemberList();
		}
	}
}
